<template>
  <div class="login">
    <div class="form">
      <h1 class="title">Sign in to Admin</h1>
      <el-form
        :model="loginForm"
        :rules="rules"
        ref="ruleForm"
        label-width="0"
        size="medium"
      >
        <el-form-item label="" prop="username">
          <el-input
            v-model.trim="loginForm.username"
            autocomplete="off"
            placeholder="请输入账号"
            @keyup.enter.native="submitForm"
          >
            <i slot="prefix" class="el-input__icon el-icon-user"></i>
          </el-input>
        </el-form-item>
        <el-form-item label="" prop="password">
          <el-input
            type="password"
            v-model.trim="loginForm.password"
            autocomplete="off"
            placeholder="请输入密码"
            @keyup.enter.native="submitForm"
          >
            <i slot="prefix" class="el-input__icon el-icon-lock"></i>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            class="submit"
            type="primary"
            @click="submitForm('ruleForm')"
            :loading="loading"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
  <script>
export default {
  name: "Login",
  data() {
    return {
      loading: false,
      loginForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [{ required: true, message: "请输入账号", trigger: "blur" }],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 6,
            max: 32,
            message: "长度在 6 到 32 个字符",
            trigger: "blur",
          },
        ],
      },
      redirect: undefined,
    };
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true
    }
  },
  methods: {
    submitForm() {
      this.$refs["ruleForm"].validate((valid) => {
        if (!valid) {
          return;
        }
        this.$router.push({ path: "/emergencyDispatch" });
        // this.loading = true;
        // this.$store
        //   .dispatch("user/login", this.loginForm)
        //   .then(() => {
        //     this.$router.push({ path: "/emergencyDispatch" });
        //   })
        //   .catch(() => {
        //     this.loading = false;
        //   });
      });
    }
  },
};
</script>
  <style lang="scss" scoped>
.login {
  display: flex;
  width: 100%;
  height: 100vh;
  min-height: 500px;
  overflow: auto;
  background-image: url("../assets/images/bg-smooth.jpg");
  background-repeat: no-repeat;
  background-position: center center;
  background-attachment: fixed;
  background-size: cover;
  align-items: center;
  .form {
    flex: none;
    width: 480px;
    padding: 60px;
    margin: 0 auto;
    border-radius: 4px;
    background-color: rgba($color: #ffffff, $alpha: 0.2);
    .title {
      font-weight: 300;
      margin-top: 0;
      margin-bottom: 60px;
      text-align: center;
      color: #ffffff;
    }
    .submit {
      margin-top: 30px;
      width: 100%;
    }
  }
}
</style>
  